package com.ruoyi.web.controller.caipiao;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.caipiao.domain.CaipiaoPl5MethodFour;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.caipiao.domain.CaipiaoPl3MethodFive;
import com.ruoyi.caipiao.service.ICaipiaoPl3MethodFiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 方法5Controller
 *
 * @author ruoyi
 * @date 2025-06-12
 */
@RestController
@RequestMapping("/caipiao/five")
public class CaipiaoPl3MethodFiveController extends BaseController {
    @Autowired
    private ICaipiaoPl3MethodFiveService caipiaoPl3MethodFiveService;

    /**
     * 生成排列5号码
     *
     * @param caipiaoPl3MethodFive
     * @return
     */
    @PreAuthorize("@ss.hasPermi('caipiao:three:list')")
    @GetMapping("/generateCode")
    public AjaxResult generateCode(CaipiaoPl3MethodFive caipiaoPl3MethodFive) {
        List<CaipiaoPl3MethodFive> adds = caipiaoPl3MethodFiveService.generateCode(caipiaoPl3MethodFive);
        caipiaoPl3MethodFiveService.saveBatch(adds);
        return success();
    }

    @PreAuthorize("@ss.hasPermi('caipiao:three:list')")
    @GetMapping("/checkCode")
    public AjaxResult checkCode(CaipiaoPl3MethodFive caipiaoPl3MethodFive) {
        List<CaipiaoPl3MethodFive> caipiaoPl3MethodFives = caipiaoPl3MethodFiveService.checkCode(caipiaoPl3MethodFive);
        if (CollectionUtil.isNotEmpty(caipiaoPl3MethodFives)) {
            caipiaoPl3MethodFiveService.updateBatchById(caipiaoPl3MethodFives);
        }
        return success();
    }

    /**
     * 查询方法5列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:five:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaipiaoPl3MethodFive caipiaoPl3MethodFive) {
        startPage();
        List<CaipiaoPl3MethodFive> list = caipiaoPl3MethodFiveService.selectCaipiaoPl3MethodFiveList(caipiaoPl3MethodFive);
        return getDataTable(list);
    }

    /**
     * 导出方法5列表
     */
    @PreAuthorize("@ss.hasPermi('caipiao:five:export')")
    @Log(title = "方法5" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaipiaoPl3MethodFive caipiaoPl3MethodFive) {
        List<CaipiaoPl3MethodFive> list = caipiaoPl3MethodFiveService.selectCaipiaoPl3MethodFiveList(caipiaoPl3MethodFive);
        ExcelUtil<CaipiaoPl3MethodFive> util = new ExcelUtil<CaipiaoPl3MethodFive>(CaipiaoPl3MethodFive.class);
        util.exportExcel(response, list, "方法5数据");
    }

    /**
     * 获取方法5详细信息
     */
    @PreAuthorize("@ss.hasPermi('caipiao:five:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(caipiaoPl3MethodFiveService.selectCaipiaoPl3MethodFiveById(id));
    }

    /**
     * 新增方法5
     */
    @PreAuthorize("@ss.hasPermi('caipiao:five:add')")
    @Log(title = "方法5" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaipiaoPl3MethodFive caipiaoPl3MethodFive) {
        return toAjax(caipiaoPl3MethodFiveService.insertCaipiaoPl3MethodFive(caipiaoPl3MethodFive));
    }

    /**
     * 修改方法5
     */
    @PreAuthorize("@ss.hasPermi('caipiao:five:edit')")
    @Log(title = "方法5" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaipiaoPl3MethodFive caipiaoPl3MethodFive) {
        return toAjax(caipiaoPl3MethodFiveService.updateCaipiaoPl3MethodFive(caipiaoPl3MethodFive));
    }

    /**
     * 删除方法5
     */
    @PreAuthorize("@ss.hasPermi('caipiao:five:remove')")
    @Log(title = "方法5" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(caipiaoPl3MethodFiveService.deleteCaipiaoPl3MethodFiveByIds(ids));
    }
}
